<?php

require_once realpath (dirname (__FILE__) . '//..//..//..//pages.php');
require_once CLASS_DATABASE;
require_once CLASS_DIV;
require_once CLASS_FORM;
require_once INC_DEFINES;

function formClasse () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'classe'
                    )
    );
    /* Adding nome */
    $form->add (new Label (
                    'Nome:',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text'
                            )
                    )
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit'
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formDistretto () {
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'distretto'
                    )
    );
    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());
    /* Adding descrizione */
    $form->add (
            new Label (
                    'Descrizione: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'descrizione',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());
    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());
    return $form;
}

function formDocente () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'docente'
                    )
    );
    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding cognome */
    $form->add (new Label (
                    'Cognome: ',
                    new Input (
                            array (
                                'name' => 'cognome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding data */
    $form->add (new Label (
                    'Data: (yyyy-mm-dd) ',
                    new Input (
                            array (
                                'id' => 'date',
                                'name' => 'data',
                                'onclick' => "fPopCalendar('date')",
                                'type' => 'text',
                            )
                    )
            )
    );

    /* Adding sesso */
    $label = new Label (
                    'Sesso: ',
                    new Input (
                            array (
                                'name' => 'sesso',
                                'type' => 'radio',
                                'value' => 'M'
                            )
                    ),
                    array (
                        'class' => 'sesso'
                    )
    );
    $label->add (new FullTag ('b', array ('style' => 'font-size: 80%;'), 'M'));

    $label->add (new Input (
                    array (
                        'name' => 'sesso',
                        'type' => 'radio',
                        'value' => 'F'
                    )
            )
    );
    $label->add (new FullTag ('b', array ('style' => 'font-size: 80%;'), 'F'));
    $form->add ($label);
    $form->add (new Br ());

    /* Adding indirizzo */
    $form->add (new Label (
                    'Indirizzo: ',
                    new Input (
                            array (
                                'name' => 'indirizzo',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding e-mail */
    $form->add (new Label (
                    'E-Mail: ',
                    new Input (
                            array (
                                'name' => 'email',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding citta */
    $form->add (new Label (
                    'Citt&agrave;: ',
                    new Input (
                            array (
                                'name' => 'citta',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding telefono */
    $form->add (new Label (
                    'Telefono: ',
                    new Input (
                            array (
                                'name' => 'telefono',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding fax */
    $form->add (new Label (
                    'Fax: ',
                    new Input (
                            array (
                                'name' => 'fax',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    $db = openConnection ();

    /* Adding scuola */
    $result = $db->select ('scuola', array ('ID, nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDscuola[]',
                'multiple' => 'multiple'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Scuola: <br />',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding materia */
    $result = $db->select ('materia', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDmateria[]',
                'multiple' => 'multiple'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Materia: <br />',
                    $select
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());
    return $form;
}

function formIndirizzo () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'indirizzo'
                    )
    );

    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding descrizione */
    $form->add (
            new Label (
                    'Descrizione: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'descrizione',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formIntervento () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'intervento'
                    )
    );

    $db = openConnection ();

    /* Adding argomenti */
    $form->add (
            new Label (
                    'Argomenti: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'argomenti',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding data */
    $form->add (new Label (
                    'Data: (yyyy-mm-dd) ',
                    new Input (
                            array (
                                'id' => 'date',
                                'name' => 'data',
                                'onclick' => "fPopCalendar('date')",
                                'type' => 'text',
                            )
                    )
            )
    );

    /* Adding ora */
    $form->add (new Label (
                    'Ora: (HH:MM:SS) ',
                    new Input (
                            array (
                                'name' => 'ora',
                                'type' => 'text',
                            )
                    )
            )
    );

    /* Adding durata */
    $form->add (new Label (
                    'Durata: ',
                    new Input (
                            array (
                                'name' => 'durata',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding docente */
    $result = $db->select ('docente', array ('ID', 'nome', 'cognome'), null, null, 'cognome');
    $select = new Select (array (
                'name' => 'IDdocente'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['cognome'] . ' ' . $row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Docente: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding giudizio */
    $form->add (
            new Label (
                    'Giudizio: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'giudizio',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding materia */
    $result = $db->select ('materia', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDmateria'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Materia: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding note */
    $form->add (
            new Label (
                    'Note: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'note',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding ospedale */
    $result = $db->select ('ospedale', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDospedale'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Ospedale: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding reparto */
    $result = $db->select ('reparto', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDreparto'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Reparto: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding ricovero */
    $result = $db->select ('ricovero', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDricovero'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Ricovero: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding studente */
    $result = $db->select ('studente', array ('ID', 'nome', 'cognome'), null, null, 'cognome');
    $select = new Select (array (
                'name' => 'IDstudente'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['cognome'] . ' ' . $row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Studente: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding tipo_intervento */
    $result = $db->select ('tipo_intervento', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDtipo_intervento'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Tipo Intervento: ',
                    $select
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formMateria () {
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'materia'
                    )
    );

    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    $form->add (
            new Label (
                    'Descrizione: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'descrizione',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formOspedale () {
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'ospedale'
                    )
    );

    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding descrizione */
    $form->add (
            new Label (
                    'Descrizione: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'descrizione',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding indirizzo */
    $form->add (new Label (
                    'Indirizzo: ',
                    new Input (
                            array (
                                'name' => 'indirizzo',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding citta */
    $form->add (new Label (
                    'Citt&agrave;: ',
                    new Input (
                            array (
                                'name' => 'citta',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding telefono */
    $form->add (new Label (
                    'Telefono: ',
                    new Input (
                            array (
                                'name' => 'telefono',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding fax */
    $form->add (new Label (
                    'Fax: ',
                    new Input (
                            array (
                                'name' => 'fax',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding email */
    $form->add (new Label (
                    'E Mail: ',
                    new Input (
                            array (
                                'name' => 'email',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    $db = openConnection ();

    /* Adding distretto */
    $result = $db->select ('distretto', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDdistretto'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Distretto: ',
                    $select
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formReparto () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'ricovero'
                    )
    );

    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());
    /* Adding descrizione */
    $form->add (
            new Label (
                    'Descrizione: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'descrizione',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formRicovero () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'ricovero'
                    )
    );

    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding data */
    $form->add (new Label (
                    'Data : (yyyy-mm-dd hh:mm:ss) ',
                    new Input (
                            array (
                                'id' => 'date',
                                'name' => 'data',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Button (
                    array (
                        'id' => 'date_button',
                        'onclick' => 'viewcalendar(event);',
                        'type' => 'button',
                    ),
                    '...'
            )
    );
    $form->add (new Br ());

    $db = openConnection ();

    /* Adding tipo_ricovero */
    $result = $db->select ('tipo_ricovero', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDtipo_ricovero'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Tipo Ricovero: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding studente */
    $result = $db->select ('studente', array ('ID', 'nome', 'cognome'), null, null, 'cognome');
    $select = new Select (array (
                'name' => 'IDstudente'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['cognome'] . ' ' . $row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Studente: ',
                    $select
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formPermesso () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'permesso'
                    )
    );

    $db = openConnection ();

    /* Getting actions */
    require_once MDL_ACTIONS;
    $actions = getActions ();
    /* Adding IDuser */
    $select = new Select (array (
                'name' => 'IDuser',
                    )
    );
    $result = $db->select ('user', array ('ID', 'username'));
    if ($result) {
        while ($row = $db->fetchAssoc ($result)) {
            $select->add (new Option ($row['username'], $row['ID']));
        }
    }
    $form->add (new Label (
                    "L'utente ",
                    $select
            )
    );
    /* Adding action */
    $select = new Select (array (
                'name' => 'action[]',
                'multiple' => 'multiple'
                    )
    );
    foreach ($actions as $key => $action) {
        $select->add (new Option ($action, $key));
    }
    $form->add (new Label (
                    ' può ',
                    $select
            )
    );
    $form->add (new Br ());
    /* Getting tables */
    require_once MDL_TABLES;
    $tables = getTables ();
    $select = new Select (array (
                'name' => 'what'
                    )
    );
    foreach ($tables as $key => $table) {
        $select->add (new Option ($table, $key));
    }
    $form->add ($select);
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formScuola () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'scuola'
                    )
    );

    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding descrizione */
    $form->add (
            new Label (
                    'Descrizione: <br />',
                    new TextArea (
                            array (
                                'cols' => 100,
                                'name' => 'descrizione',
                                'rows' => 10
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding indirizzo */
    $form->add (new Label (
                    'Indirizzo: ',
                    new Input (
                            array (
                                'name' => 'indirizzo',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding citta */
    $form->add (new Label (
                    'Citt&agrave;: ',
                    new Input (
                            array (
                                'name' => 'citta',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding telefono */
    $form->add (new Label (
                    'Telefono: ',
                    new Input (
                            array (
                                'name' => 'telefono',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding fax */
    $form->add (new Label (
                    'Fax: ',
                    new Input (
                            array (
                                'name' => 'fax',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding email */
    $form->add (new Label (
                    'E Mail: ',
                    new Input (
                            array (
                                'name' => 'email',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    $db = openConnection ();

    /* Adding distretto */
    $result = $db->select ('distretto', array ('ID', 'nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDdistretto'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Distretto: ',
                    $select
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formStudente () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'studente'
                    )
    );
    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());
    /* Adding cognome */
    $form->add (new Label (
                    'Cognome: ',
                    new Input (
                            array (
                                'name' => 'cognome',
                                'type' => 'text'
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding data */
    $form->add (new Label (
                    'Data: (yyyy-mm-dd) ',
                    new Input (
                            array (
                                'id' => 'date',
                                'name' => 'data',
                                'onclick' => "fPopCalendar('date')",
                                'type' => 'text',
                            )
                    )
            )
    );

    /* Adding telefono */
    $form->add (new Label (
                    'Telefono: ',
                    new Input (
                            array (
                                'name' => 'telefono',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding email */
    $form->add (new Label (
                    'E Mail: ',
                    new Input (
                            array (
                                'name' => 'email',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding sesso */
    $div = new Div (array ('id' => 'sesso'));
    $sesso = new Label (
                    'Sesso: ',
                    new Input (
                            array (
                                'name' => 'sesso',
                                'type' => 'radio',
                                'value' => 'M'
                            )
                    )
    );

    $sesso->add (new FullTag ('b', array ('style' => 'font-size: 80%;'), 'M'));

    $sesso->add (new Input (
                    array (
                        'name' => 'sesso',
                        'type' => 'radio',
                        'value' => 'F'
                    )
            )
    );
    $sesso->add (new FullTag ('b', array ('style' => 'font-size: 80%;'), 'F'));
    $div->add ($sesso);
    $form->add ($div);
    $form->add (new Br ());

    /* Adding indirizzo */
    $form->add (new Label (
                    'Indirizzo: ',
                    new Input (
                            array (
                                'name' => 'indirizzo',
                                'type' => 'text'
                            )
                    )
            )
    );
    $form->add (new Br ());

    $db = openConnection ();

    /* Adding classe */
    $result = $db->select ('classe', array ('ID, nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDclasse'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Classe: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding scuola */
    $result = $db->select ('scuola', array ('ID, nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDscuola'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Scuola: ',
                    $select
            )
    );
    $form->add (new Br ());

    /* Adding indirizzo */
    $result = $db->select ('indirizzo', array ('ID, nome'), null, null, 'nome');
    $select = new Select (array (
                'name' => 'IDindirizzo'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    'Indirizzo: ',
                    $select
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formSupervisiona () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'supervisiona'
                    )
    );

    /* Adding users */
    $db = openConnection ();
    $result = $db->select ('user', array ('ID', 'username'), null, null, 'username');
    $select = new Select (array (
                'name' => 'IDuser',
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['username'], $row['ID']));
    }
    $form->add (new Label (
                    'L&apos;utente ',
                    $select
            )
    );

    /* Adding studente */
    $result = $db->select ('studente', array ('ID', 'nome', 'cognome'), null, null, 'cognome, nome');
    $select = new Select (array (
                'name' => 'IDstudente'
                    )
    );
    for ($i = 0; $row = mysql_fetch_assoc ($result); $i++) {
        $select->add (new Option ($row['cognome'] . ' ' . $row['nome'], $row['ID']));
    }
    $form->add (new Label (
                    ' può supervisionare lo studente ',
                    $select
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formTipoIntervento () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'tipo_intervento'
                    )
    );
    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formTipoRicovero () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'tipo_intervento'
                    )
    );
    /* Adding nome */
    $form->add (new Label (
                    'Nome: ',
                    new Input (
                            array (
                                'name' => 'nome',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

function formUser () {
    /* Creating form */
    $form = new Form (
                    array (
                        'method' => 'post',
                        'name' => 'user'
                    )
    );
    /* Adding username */
    $form->add (new Label (
                    'Username: ',
                    new Input (
                            array (
                                'name' => 'username',
                                'type' => 'text',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding password */
    $form->add (new Label (
                    'Password: ',
                    new Input (
                            array (
                                'name' => 'password',
                                'type' => 'password',
                            )
                    )
            )
    );
    $form->add (new Br ());

    /* Adding last login */
    $form->add (new Label (
                    'Ultimo login: ',
                    new Input (
                            array (
                                'name' => 'last_login',
                                'readonly' => 'readonly',
                                'type' => 'text',
                            )
                    ),
                    array ('id' => 'lbl_last_login')
            )
    );
    $form->add (new Br ());

    $form->add (new Button (
                    array (
                        'type' => 'submit',
                    ),
                    'Invia'
            )
    );
    $form->add (new Br ());

    return $form;
}

?>
